#ifdef MBM_IMIBASE_SUPPORT

#include "mbm_spreadtrum_inc.h"

#include "mbm_typedefine.h"
#include "mbm_isp_adapter.h"
#include "mbm_adapter.h"

//#define MBM_ISP_DEBUG

#if defined(MBM_ISP_DEBUG)
#define MBM_ISP_TRACE mbm_trace
#else
#define MBM_ISP_TRACE 
#endif

typedef struct
{
	ISP_SCALE_PARAM_T isp_scale;
} t_mbm_isp_cntx;

//extern variable

//extern function

//static or gloable variable
static t_mbm_isp_cntx g_mbm_isp_cntx = {0};

//static function
const UInt32 g_mbm_isp_data_yuv422 = ISP_DATA_YUV422;
const UInt32 g_mbm_isp_data_yuv420 = ISP_DATA_YUV420;

static uint32 mbm_get_yuv_addr(ISP_DATA_ADDR_T addr, uint32 width,uint32 height)
{
	return 0;
}

Int32 mbm_isp_init(void)
{
	//scale
	g_mbm_isp_cntx.isp_scale.get_scale_data = mbm_get_yuv_addr;		
	ISP_ServiceInit();
	return (Int32)&g_mbm_isp_cntx;
}

void mbm_isp_do_scale(Int32 handle, UInt32 inFmt,
		 UInt32 w0, UInt32 h0, UInt32 y_addr, UInt32 uv_addr, UInt32 src_buf_size, 
		 UInt32 w1, UInt32 h1, UInt32 disp_addr, UInt32 disp_buf_size)
{
	t_mbm_isp_cntx* cntx = (t_mbm_isp_cntx*)handle;
	cntx->isp_scale.input_format = (ISP_DATA_FORMAT_E)inFmt;
	cntx->isp_scale.output_format = ISP_DATA_RGB565;	
	
	SCI_ASSERT(handle);
	//scale
	cntx->isp_scale.input_size.w = w0;
	cntx->isp_scale.input_size.h = h0;

	cntx->isp_scale.input_rect.x = 0x00;
	cntx->isp_scale.input_rect.y = 0x00;
	cntx->isp_scale.input_rect.w = w0;
	cntx->isp_scale.input_rect.h = h0;
	
	cntx->isp_scale.input_addr.y_addr = y_addr;
	cntx->isp_scale.input_addr.uv_addr = uv_addr;
	cntx->isp_scale.input_buf_size = src_buf_size;
	
	cntx->isp_scale.output_size.w = w1;
	cntx->isp_scale.output_size.h = h1;

	cntx->isp_scale.output_addr.y_addr = disp_addr;
	cntx->isp_scale.output_addr.uv_addr = 0;
	cntx->isp_scale.output_buf_size = disp_buf_size;

	ISP_ServiceOpen();
	if(SCI_SUCCESS == ISP_ServiceSetScaleParam(&(cntx->isp_scale)))
	{
		ISP_ServiceStartScale(); 
		MBM_ISP_TRACE("ISP_ServiceSetScaleParam ok");
	}
	else
	{
		MBM_ISP_TRACE("Assert! ISP_ServiceSetScaleParam fail");
	}	 
}

void mbm_isp_close(Int32 handle)
{
	uint32 rtn = SCI_SUCCESS;

	SCI_ASSERT(handle);
	
	memset(handle, 0, sizeof(t_mbm_isp_cntx));
	
	rtn = ISP_ServiceFeatureStop();
	MBM_ISP_TRACE("ISP_ServiceFeatureStop rtn=%d", rtn);
	ISP_ServiceClose();
}

#endif /* MBM_IMIBASE_SUPPORT */

